package com.htudata.zabbix.api.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TemplateZabbixApiService {

  @Autowired
  private BaseZabbixApiService baseZabbixApiService;

  public String createTemplates(JSONArray templates)  throws Exception{
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.create");
    request.put("params", templates);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  public String updateTemplates(JSONArray templates)  throws Exception{
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.update");
    request.put("params", templates);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  public String deleteTemplates(JSONArray templateIds) throws Exception {
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.delete");
    request.put("params", templateIds);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  public String getTemplates(JSONObject params) throws Exception {
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  @Deprecated
  private JSONArray getTemplateDataByGroupId(String[] output, String[] groupids, String[] selectHosts, String[] selectParentTemplates, String selectItems, String selectTriggers, String selectGraphs) throws Exception {
    JSONObject params = new JSONObject();
    params.put("output", output);
    params.put("groupids", groupids);
    params.put("selectHosts", selectHosts);
    params.put("selectParentTemplates", selectParentTemplates);
    params.put("selectItems", selectItems);
    params.put("selectTriggers", selectTriggers);
    params.put("selectGraphs", selectGraphs);
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONArrayResult(request);
  }
  
  @Deprecated
  private JSONArray getTemplateDataByHostId(String[] output, String[] hostids, String[] selectHosts, String[] selectParentTemplates, String selectItems, String selectTriggers, String selectGraphs)  throws Exception{
    JSONObject params = new JSONObject();
    params.put("output", output);
    params.put("hostids", hostids);
    params.put("selectHosts", selectHosts);
    params.put("selectParentTemplates", selectParentTemplates);
    params.put("selectItems", selectItems);
    params.put("selectTriggers", selectTriggers);
    params.put("selectGraphs", selectGraphs);
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONArrayResult(request);
  }
  
  @Deprecated
  private JSONArray getTemplateInfoByHostId(String[] output, String[] hostids) throws Exception {
    JSONObject params = new JSONObject();
    params.put("output", output);
    params.put("hostids", hostids);
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONArrayResult(request);
  }
  
  @Deprecated
  private JSONArray getTemplateInfoByTemplateId(String[] output, String[] templateids) throws Exception {
    JSONObject params = new JSONObject();
    params.put("output", output);
    params.put("templateids", templateids);
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "template.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONArrayResult(request);
  }
}
